package com.buddy.syn.method._02;

/**
 * 非线程安全问题  存在于实例变量中，如果方法内部的私有变量则不存在非线程安全问题，即都是线程安全的
 */
public class HasSelfPrivateNum {
    private int num = 0;
    synchronized public void add(String userName){
        try {
            if (userName.equals("a")){
                num = 100;
                System.out.println("a set over !");
                Thread.sleep(2000);
            }else {
                num = 200;
                System.out.println("b set over !");
            }
            System.out.println(userName + " num= "+num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
